package com.it.learn.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author xyx
 * @date 2018-10-16 20:06
 */
@RestController
@RequestMapping("/ribbon")
public class ConsumerController {

	@Autowired
	RestTemplate restTemplate;

	@GetMapping("/add/{a}/{b}")
	@HystrixCommand(fallbackMethod = "addServiceFallback")
	public String add(@PathVariable int a,@PathVariable int b) {
		return restTemplate.getForEntity("http://base-service/num/add/"+a+"/"+b, String.class).getBody();
	}

	//服务调用失败调用的方法
	String addServiceFallback(int a, int b) {
		return "服务不可用";
	}


}
